package cn.fsd.controller;

import cn.fsd.exception.AppException;
import cn.fsd.exception.SubStationExceptionCodeMsg;
import cn.fsd.expection.AppExceptionCodeMsg;
import cn.fsd.service.impl.StationServiceImpl;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/station")
public class StationController {

  @Autowired
  StationServiceImpl stationService;

  @GetMapping("/all")
  @ApiOperation(value = "获取全部分站")
  public ResultBean getAllStationName(){
    return ResultBean.success(stationService.getAllStationNames());
  }

  @GetMapping("/{id}")
  @ApiOperation(value="根据id获取分站信息")
  public ResultBean getStationById(@PathVariable("id")String station_id){
    if(StringUtils.isEmpty(station_id)){
      throw new AppException(SubStationExceptionCodeMsg.STATION_ID_EMPTY);
    }
    return ResultBean.success(stationService.getStationById(station_id));
  }


}
